package cn.jiyun.exception;


import cn.jiyun.exception.exception.PasswordErrorException;
import cn.jiyun.exception.exception.UsernameNotExistException;
import cn.jiyun.result.Result;

import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;


/**
 * @TODO:
 * @Author:baimu
 * @Date:2024 12 03 14 54
 **/

@RestControllerAdvice
//@Slf4j
public class GlobalException {

    /**
     * 匹配异常类型
     * @param e
     * @return
     */
    @ExceptionHandler( UsernameNotExistException.class)
    public Result usernameNotExistException(UsernameNotExistException e){
//        log.info("匹配异常类型usernameNotExistException,code:{},msg:{}",e.getResultCodeEnum().getCode(),e.getResultCodeEnum().getMsg());
        e.printStackTrace();
        return Result.fail(e.getResultCodeEnum());
    }

    @ExceptionHandler( PasswordErrorException.class)
    public Result passwordErrorException(PasswordErrorException e){
//        log.info("匹配异常类型passwordErrorException,code:{},msg:{}",e.getResultCodeEnum().getCode(),e.getResultCodeEnum().getMsg());
        e.printStackTrace();
        return Result.fail(e.getResultCodeEnum());
    }
}
